package ms.unicorn.modellanguage;

import ms.unicorn.util.ConfigUtil;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EcoreFactory;

public class ElementAnnotation {
	private String name;
	public final AnnotatedParamList details;
	
	public ElementAnnotation(IConfigurationElement config) {
		details = new AnnotatedParamList(config);
		load(config);
		
	}
	
	protected void load(IConfigurationElement config) {
		name = ConfigUtil.get(config, "name", name);
	}

	public EAnnotation createEAnnotation() {
		EAnnotation annotation = EcoreFactory.eINSTANCE.createEAnnotation();
		annotation.setSource(name);
		for(IConfigurationElement child: details.config.getChildren("param"))
			annotation.getDetails().put(child.getAttribute("name"), child.getAttribute("value"));
		return annotation;
	}
		
	public String getType() {
		return name;
	}
}
